package tv.youxing.android.ui;

import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

import com.kymjs.rxvolley.RxVolley;
import com.kymjs.rxvolley.client.HttpCallback;
import com.kymjs.rxvolley.client.HttpParams;

import butterknife.BindView;
import butterknife.ButterKnife;
import tv.youxing.android.Interface.CustomToobarImp;
import tv.youxing.android.R;
import tv.youxing.android.custom.CustomToolbar;
import tv.youxing.android.entity.MyInfoModel;
import tv.youxing.android.utils.AppConst;
import tv.youxing.android.utils.GsonUtils;
import tv.youxing.android.utils.ShareUtils;
import tv.youxing.android.utils.StaticClass;

import static com.mob.MobSDK.getContext;

public class IntegralActivity extends BaseActivity {

    @BindView(R.id.tb)
    CustomToolbar tb;
    @BindView(R.id.balance)
    TextView balance;
    private MyInfoModel mAlldata;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_integral);
        ButterKnife.bind(this);
        initView();
        loadData();
    }


    void initView() {
    tb.setBackClickLister(new CustomToobarImp.back() {
        @Override
        public void onclick() {
            finish();
        }
    });
    }

    void loadData() {
        HttpParams params = new HttpParams();
        params.putHeaders("Authorization", "Bearer " + ShareUtils.getString(getContext(), AppConst.TOKEN, ""));

        RxVolley.post(StaticClass.MyInfo, params, new HttpCallback() {
            @Override
            public void onSuccess(String t) {
                mAlldata = GsonUtils.GsonToBean(t, MyInfoModel.class);


                if (mAlldata.getCode() == AppConst.TOKENERROR) {
                    IntegralActivity.this.startActivity(new Intent(IntegralActivity.this,LoginActivity.class));
                    return;
                }

                initData();
            }
        });
    }

    void initData() {
        balance.setText("￥:"+mAlldata.getResult().getBalance().toString());
    }
}
